<?php

#####特殊UI元素辅助#####
#生成地址下拉
function b_area($p=0,$c=0,$d=0,$s=0) {
	$area_p = array();
	$area_c = array();
	$area_d = array();
	$area_s = array();
	
	$province = D('CommArea')->where("pid=0")->order(ORDER)->select();
	foreach ($province as $p) {
		$area_p[$p['id']] = $p['name'];
		$city = D('CommArea')->where("pid=".$p['id'])->order(ORDER)->select();
		foreach ($city as $c) {		
			$area_c[$c['id']] = $c['name'];
			$district = D('CommArea')->where(" pid=".$c['id'])->order(ORDER)->select();
			foreach ($district as $d) {		
				$area_d[$d['id']] = $d['name'];
				$street = D('CommArea')->where("pid=".$d['id'])->order(ORDER)->select();
				foreach ($street as $s) {		
					$area_s[$s['id']] = $s['name'];
				}
			}
		}
	}
	
	$str  = '';
	$str .= c_select("province_id",$area_p,$p);
	$str .= c_select("city_id",$area_c,$c);
	$str .= c_select("district_id",$area_d,$d);
	$str .= c_select("street_id",$area_s,$s);
	return $str;
}

//联动标签 table要联动的表 pid_value联动的初始pid pid_file联动的pid id_file联动的id
function b_link_table($title,$table,$array_file,$array_file_vo,$pid_value='0',$pid_file='pid',$id_file='id'){
	$js  = "<script type='text/javascript'> $().ready(function(e) {";
	$str = '';
    foreach ($array_file as $key => $value) {
    	if(!isset($array_file_vo)||(is_null($array_file_vo[0])||$array_file_vo[0]==$array_file_vo[1])){//如果没有设置  $array_file_vo 字段默认值 
	        $pidvalue=$pid_value;
			$value = rs2select(D($table)->where($pid_file.'='.$pidvalue)->select());
			$pid_value=key($value);//获取数组中第一个键值
			$str  .= c_select($array_file[$key], $value,0);
    	}else{
    		$pidvalue_infos=$key==0?$pidvalue_infos=$pid_value:$array_file_vo[$key-1];
			$value = rs2select(D($table)->where($pid_file.'='.$pidvalue_infos)->select());
			$str  .= c_select($array_file[$key], $value,$array_file_vo[$key]);
    	}  
			$array =json_encode( array_slice($array_file, $key+1,count($array_file)));//截取参数个数 为了jq赋值 知道下一级的id
			$js   .='$("#'.$array_file[$key].'").bind("change",function(){ loadArea_new('.$array.',$(this).val(),0,"'.$table.'"); });';
     } 
     	$js .= "}); </script>";
	$str .= $js;
    $b_div=b_div($title,$str,$tips);
	return $b_div;
}



#生成地址下拉（在一个select中）
function b_areas($name, $selected=0) {
	$str = "<select name='{$name}' id='{$name}'><option value='0'>===请选择===</option>";
	$province = D('CommArea')->where("pid=0")->order(ORDER)->select();
	#省
	foreach ($province as $p) {
		$str .= '<option value="'.$p['id'].'" '.($selected==$p['id'] ? ' selected="selected"' : '').'>'.$p['name'].'</option>';
		$city = D('CommArea')->where("pid=".$p['id'])->order(ORDER)->select();
		#市
		foreach ($city as $c) {		
			$str .= '<option value="'.$c['id'].'" '.($selected==$c['id'] ? ' selected="selected"' : '').'>&nbsp;&nbsp;┗'.$c['name'].'</option>';
			$district = D('CommArea')->where(" pid=".$c['id'])->order(ORDER)->select();
			#区	
			foreach ($district as $d) {		
				$str .= '<option value="'.$d['id'].'" '.($selected==$d['id'] ? ' selected="selected"' : '').'>&nbsp;&nbsp;&nbsp;&nbsp;┗'.$d['name'].'</option>';
				/*
				$street = D('CommArea')->where("pid=".$d['id'])->order(ORDER)->select();
				#街道
				foreach ($street as $s) {		
					$str .= '<option value="'.$s['id'].'" '.($selected==$s['id'] ? ' selected="selected"' : '').'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;┗'.$s['name'].'</option>';
				}
				*/
			}
		}
	}
	$str .='</select>';
	return $str;
}

#生成商品分类下拉
function b_goods_type($name, $selected=0) {
	$str = "<select name='{$name}' id='{$name}'><option value='0'>===请选择===</option>";
	$province = D('GoodsType')->where("pid=0")->order(ORDER)->select();
	#1
	foreach ($province as $p) {
		$str .= '<option value="'.$p['id'].'" '.($selected==$p['id'] ? ' selected="selected"' : '').'>'.$p['name'].'</option>';
		$city = D('GoodsType')->where("pid=".$p['id'])->order(ORDER)->select();
		#2
		foreach ($city as $c) {		
			$str .= '<option value="'.$c['id'].'" '.($selected==$c['id'] ? ' selected="selected"' : '').'>&nbsp;&nbsp;┗'.$c['name'].'</option>';
			$district = D('GoodsType')->where(" pid=".$c['id'])->order(ORDER)->select();
			#3
			foreach ($district as $d) {		
				$str .= '<option value="'.$d['id'].'" '.($selected==$d['id'] ? ' selected="selected"' : '').'>&nbsp;&nbsp;&nbsp;&nbsp;┗'.$d['name'].'</option>';
			}
		}
	}
	$str .='</select>';
	return $str;
}

#生成会员信息label
function b_user($value) {
	return b_text('会员','user_id',$value,'请填入会员ID');
}

#####后台表单元素辅助函数#####
function b_div($title='',$value='',$tips='') {
	$str = '
	<div class="control-group">
		<label class="control-label" for="typeahead">'.$title.'</label>
			<div class="controls">
				'.$value.'
				'.($tips=='' ? '' : '<p class="help-block">'.$tips.'</p>').'
		  </div>
	</div>';
	echo $str;
}

function b_label($title, $value='', $tips=''){
	$htm = c_label($value);
	b_div($title,$htm,$tips);
}

function b_label2($value='', $tips=''){
	$str = '
	<div class="control-group">
			<div class="controls" style="margin-left:20px;">
				'.$value.'
				'.($tips=='' ? '' : '<p class="help-block">'.$tips.'</p>').'
		  </div>
	</div>';
	echo $str;
}

   // {:b_text('姓名','%realname%',$realname)}
function b_text($title, $name, $value='', $tips=''){
	// %realname%,''
	$htm = c_text($name,$value);
	b_div($title,$htm,$tips);
}

function b_img($title, $name, $value='', $tips=''){
	$htm = c_img($name,$value);
	b_div($title,$htm,$tips);
}

function b_map($title, $name, $value='', $tips='沈阳'){
	$htm = c_text($name,$value);
	b_div($title,$htm,'<a href="http://api.map.baidu.com/lbsapi/getpoint/index.html" target="_blank">点击这里获取坐标</a>&nbsp;'.$tips);	
}

function b_textarea($title='', $name='', $value='', $tips=''){
	$htm = c_textarea($name,$value);
	b_div($title,$htm,$tips);	
}
function b_hidden($name, $value=''){
	$htm = c_hidden($name,$value);
	echo $htm;
}

function b_pwd($title, $name, $tips=''){
	$htm = c_pwd($name,$value);
	b_div($title,$htm,$tips);
}

function b_date($title, $name, $value='', $tips=''){
	$htm = c_date($name,$value);
	b_div($title,$htm,$tips);
}

function b_datetimer($title='', $name='', $value='', $tips=''){
	$htm = c_datetime($name,$value);
	b_div($title,$htm,$tips);
}

// ('注册时间',$time_start,$time_end)}
function b_date_2($title, $v1='', $v2='',$tips='',$file=''){
	$htm = c_date_2($v1,$v2,$file);
	b_div($title,$htm,$tips);
}

function b_editor($title, $name, $value='', $tips=''){
	$htm = c_editor($name,$value);
	b_div($title,$htm,$tips);	
}
// '主治项目','treat_id',$treat_list,$vo['treat_id']
function b_select($title,$name, $all_value, $select_value='', $default_value='',$class='',$tips='',$order=true) {
	if (!is_array($all_value)) $all_value = $GLOBALS[$all_value];
	if (!isset($all_value[0])) $all_value[0] = "==请选择==";
	if ($order) ksort($all_value);
	if ($name=='state' && $select_value=="") $select_value = 1;
	$htm = c_select($name, $all_value, $select_value, $class, $attr,$default_value);
	b_div($title,$htm,$tips);	
}

// select选项 需要在添加和修改的时候 都需要 能用的上
function b_select_id_name($title,$name,$dbname,$id='id',$fname='name',$select_value='', $level='',$level_jibie='', $default_value='',$class='',$tips='',$order=true) {
	$all_value=dbidname($dbname,$id,$fname,$level,$level_jibie);
	if (!is_array($all_value)) $all_value = $GLOBALS[$all_value];
	if (!isset($all_value[0])) $all_value[0] = "==请选择==";
	if ($order) ksort($all_value);
	if ($name=='state' && $select_value=="") $select_value = 1;
	$htm = c_select($name, $all_value, $select_value, $class, $attr,$default_value);
	b_div($title,$htm,$tips);	
}


function b_select3($title,$name, $all_value, $select_value='', $default_value='',$class='',$tips='',$order=true) {
	if (!is_array($all_value)) $all_value = $GLOBALS[$all_value];

//	if ($order) ksort($all_value);
	if ($name=='state' && $select_value=="") $select_value = 1;

	$htm = c_select($name, $all_value, $select_value, $class, $attr,$default_value);
	b_div($title,$htm,$tips);
}

function b_select_2($title,$name, $all_value, $select_value='', $default_value='',$class='',$tips='',$order=true) {
    if (!is_array($all_value)) $all_value = $GLOBALS[$all_value];
    if ($order) ksort($all_value);
    if ($name=='state' && $select_value=="") $select_value = 1;

    $htm = c_select($name, $all_value, $select_value, $class, $attr,$default_value);
    b_div($title,$htm,$tips);
}

function b_select_mod($title,$name,$mod,$field='name',$select_value='', $default_value='',$class='',$tips='',$where='',$order='id DESC') {
	$list = D($mod)->where($where)->order($order)->select();
	$all_value  = array();
	if (!isset($all_value[0])) $all_value[0] = "==请选择==";
	foreach ($list as $l) {
		$all_value[$l['id']] = $l[$field];
	}
	$htm = c_select($name, $all_value, $select_value, $class, $attr,$default_value);
	b_div($title,$htm,$tips);	
}





function b_checkbox_mod($title,$name,$mod,$field='name',$select_value='', $default_value='',$class='',$tips='',$where='',$order='id DESC') {
	$list = D($mod)->where($where)->order($order)->select();
	$all_value  = array();
	foreach ($list as $l) {
		$all_value[$l['id']] = $l[$field];
	}
	
	$htm = c_checkbox($name, $all_value, $select_value, $class, $attr,$default_value);
	b_div($title,$htm,$tips);	
}

function b_radio($title, $name, $all_value, $select_value='',$default_value='',$class='',$tips='') {
	if (!is_array($all_value)) $all_value = $GLOBALS[$all_value];
	
	$htm = c_radio($name, $all_value, $select_value,$class,$attr);
	b_div($title,$htm,$tips);	
}

function b_checkbox($title, $name, $all_value, $select_value='',$default_value='',$class='',$tips='') {
	if (!is_array($all_value)) $all_value = $GLOBALS[$all_value];
	if (!is_array($select_value)) {
		$select_value = trim($select_value,'#');
		$select_value = explode('##',$select_value);
	}
	
	$htm = c_checkbox($title, $name, $all_value, $select_value, $class, $attr);
	b_div($title,$htm,$tips);
}

function b_upload($title,$name,$value='',$num=1, $tips='') {
	$htm = c_upload($name, $value, $num);
	b_div($title,$htm,$tips);
}

function b_upload_video($title,$name,$value='',$num=1, $tips='') {
    $htm = c_upload_video($name, $value, $num);
    b_div($title,$htm,$tips);
}

function b_uploads($title,$name,$value='',$num=1, $tips='') {
	$htm = c_uploads($name, $value, $num);
	b_div($title,$htm,$tips);
}


function b_permission($title,$name,$all_value,$select_value,$tips='') {
	$select_value = (array)unserialize($select_value);
	$str = '<select name="'.$name.'" id="'.$name.'" size="10" multiple="multiple" >';
	foreach ($GLOBALS[$all_value] as $key=>$vals) {
		$str.='<optgroup label="'.$key.'">';
		foreach ($vals as $k=>$v) {
			$str.='<option value="'.$v.'" '.(in_array($v,$select_value) ? ' selected' : '').'>'.$k.'</option>';
		}
		$str.='</optgroup>';
	}
	$str.='</select>';
	
	echo '
	<div class="control-group" id="div_'.$name.'">
		<label class="control-label" for="'.$name.'">'.$title.'</label>
			<div class="controls">
				'.$str.'
				'.($tips=='' ? '' : '<p class="help-block">'.$tips.'</p>').'
		  </div>
	</div>';
}

function b_btn($name="提交",$ret="返回",$ret_click="history.back();") {
	echo '<div class="form-actions">';
	if ($name) echo c_btn('submit', $name);
	if ($ret)  echo c_btn('button', $ret, $ret_click,'btn ml20');	
	echo '</div>';
}


#####后台表单页面辅助函数#####
function b_form_header($name,$action="") {
	echo '
	<form id="formMain" name="formMain" class="form-horizontal" action="'.U($action).'" method="post">
		<fieldset>
			<div id="legend" class="">
				<legend class="">'.$name.'</legend>
			</div>
	';
}

function b_form_header2($name,$action="") {
	echo '
	<form id="form1" class="form-horizontal" action="'.U($action).'" method="post"  enctype="multipart/form-data" >
		<fieldset>
			<div id="legend" class="">
				<legend class="">'.$name.'</legend>
			</div>
	';
}

function b_form_footer($ok='提交',$ch='返回',$ret='history.back();') {
	if ($ok || $ch ) b_btn($ok,$ch,$ret);
	echo '
		</fieldset>
	</form>
	';
}

function b_form_footer2($ok='返回',$act='javascript::history.back();') {
	echo '
	<div class="form-actions">
	  <a class="btn btn-info " href="'.$act.'"> '.$ok.' </a>
	</div>	
	';
	echo '
		</fieldset>
	</form>
	';
}

#####表格页面辅助函数#####
function b_table_header($text) {
	$tr = explode(',',$text);
	echo '
	<table class="table table-striped table-bordered bootstrap-datatable ">
	  <thead>
		  <tr>';
	foreach ($tr as $t) 
		echo '<th>'.$t.'</th>';
	echo'
		  </tr>
	  </thead>   
	  <tbody>
	';

}

function b_table_footer() {
	echo '
		</tbody>
	</table> 	
	';
}

function table_header($name,$btns=array(),$out=false) {
	echo '<div id="legend" class="" >
			<legend>'.$name.'</legend>';
	
	echo '<div class="fr" style="margin-top:-47px; margin-right:3px;">
			<div class="fl btn-group" >';
	if (!empty($btns)) {
		foreach ($btns as $name=>$link) {
			echo '<a class="btn btn-mini" href="'.($link=='' ? U(MODULE_NAME.'/'.CONTROLLER_NAME.'/add') : $link).'">'.$name.'</a>';
		}
	}
	echo '</div>';
	
	if ($out) {
		echo '<div class="fl" >&nbsp;&nbsp;<button type="submit" name="out" value="1" class="btn btn-inverse">导出结果到Excel</button></div>';
	}
	
	echo '</div>
	</div>';
}

function table_data($data,$show,$sel=false) {
	$str = '';
	$th = array();
	$tb = array();
	$s1 = explode(',',$show);
	foreach ($s1 as $k) {
		$it = explode(':',$k);
		$rth = explode('|',$it[1]);//"操作" 显示汉字
		$rtb = explode('|',$it[0]);//"id|get_comm_btn"	
		$th[] = $rth;
		$tb[] = $rtb;
	}
	#表头项
	$str .='<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-hover "><thead><tr>';	
	if ($sel) $str.='<th style="width:30px"><input type="checkbox" id="sel_all" /></th>';
	foreach ($th as $h) {

		$str.='<th '.(isset($h[1]) ? 'style="width:'.$h[1].'"' : '').'>'.$h[0].'</th>';
	}
	$str.='</tr></thead>';
	// $tb=array(array('id','get_comm_btn'),array('add_time','get_datetime'));
	#表数据	
	$str.='<tbody>';
	foreach ($data as $dk=>$value) {

		$str .='<tr>';
		if ($sel) $str.='<th style="width:30px"><input name="ids[]" class="ids" type="checkbox" value="'.$value['id'].'" /></th>';		
		//$tb相当于 "id|get_comm_btn"=> array('id','get_comm_btn')
		foreach ($tb as $b) {
			if (isset($b[1])) {
				if ($b[1]=='get_name') { //如果是get_name的话 会保存到 global中
					$txt = $b[1]($value[$b[0]],$b[0]); 	
				}else if ($b[1]=='get_comm_btn') {
					$txt = '<div class="btn-group" >
            					<a class="btn btn-mini btn-success" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/edit?'.$value['primaryfileinfo'].'='.$value[$value['primaryfileinfo']]).'">编辑</a>
            					<a class="btn btn-mini js-confirm" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/del?'.$value['primaryfileinfo'].'='.$value[$value['primaryfileinfo']]).'">删除</a>           
           					</div>'; 	
				} else {
					if (strpos($b[1],'=')!==false) {
						//判断函数后是否有 = 如果有= 就会有参数
						$tmp  = explode('=',$b[1]);
						$func = $tmp[0];
						//通过 % 来参数截取
						$args = explode('%',$tmp[1]);
						// ==================================
                        $param='';
                        for ($i=0; $i <count($args) ; $i++) {
                        	if(strpos($args[$i],'DB@')!==false){
                        	   $param_file_value=str_replace('DB@','',$args[$i]);	
                               $param.=$value[$param_file_value].',';
                        	}else{
                               $param.=$args[$i].',';
                        	}
                        }
                         $param=rtrim($param,',');
                         $param=ltrim($param,'###');
                         $param_array=explode(',',$value[$b[0]].$param);
                          if(isset($param_array[2])){
                              $txt = $func($param_array[0],$param_array[1],$param_array[2]);
                          }elseif(isset($param_array[1])){
                              $txt = $func($param_array[0],$param_array[1]);
                          }else{
                          	  $txt = $func($param_array[0]);
                          }
                          // ===============================
						// if (isset($args[2])) {                                                                 
						// 	$txt = $func(str_replace('###',$value[$b[0]],$args[0]), str_replace('###',$value[$b[0]],$args[1]), str_replace('###',$value[$b[0]],$args[2]));
						// } elseif (isset($args[1])) {
						// 	$txt = $func(str_replace('###',$value[$b[0]],$args[0]), str_replace('###',$value[$b[0]],$args[1]) );
						// } else {
						// 	$txt = $func(str_replace('###',$value[$b[0]],$args[0]));
						// }
					} else {

						$txt = $b[1]($value[$b[0]],CONTROLLER_NAME,$b[0]); 	
					}
				}
			} else {
				$txt = $value[$b[0]];
			}
			$str.='<td>'.$txt.'</td>';
		}		
		$str .='</tr>';
	}
	$str.='</tbody>';	
	$str.='</table>';	
	echo $str;
}


function table_footer($page,$btn='') {
	echo '<div class="page">'.$page.'</div>';
	if ($btn) {
		echo '<div class="foot-btns"><input type="submit" value="'.$btn.'" class="btn " /></div>';
	}
	echo '</form>';
}

function get_edit_btn($id) {
	$txt = '<div class="btn-group" >
				<a class="btn btn-mini btn-success" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/edit?id='.$id).'">编辑</a>
			</div>'; 	
	return $txt;
}

function get_del_btn($id) {
	$txt = '<div class="btn-group" >
				<a class="btn btn-mini js-confirm" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/del?id='.$id).'">删除</a>
			</div>'; 	
	return $txt;
}

function get_view_btn($id) {
	$txt = '<div class="btn-group" >
				<a class="btn btn-mini btn-success" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/edit?id='.$id).'">查看</a>
			</div>'; 	
	return $txt;
}

function get_view_del_btn($id) {
	$txt = '<div class="btn-group" >
				<a class="btn btn-mini btn-success" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/edit?id='.$id).'">查看</a>
				<a class="btn btn-mini js-confirm" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/del?id='.$id).'">删除</a>    				
			</div>'; 	
	return $txt;
}

function get_edit_view_del_btn($id) {
	$txt = '<div class="btn-group" >
				<a class="btn btn-mini btn-success" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/edit?id='.$id).'">编辑</a>	
				<a class="btn btn-mini btn-success" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/edit?id='.$id).'">查看</a>
				<a class="btn btn-mini js-confirm " href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/del?id='.$id).'">删除</a>    				
			</div>'; 	
	return $txt;
}


function get_state_btn($id,$mod,$idinfo) {
	$tmp = D($mod)->find($id);
	$txt = '<div class="btn-group" >
				'.($tmp['sy_type']==0 ?  '<a class="btn btn-mini btn-danger js-confirm" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/dostate?'.$idinfo.'='.$id).'">通过审核</a>':'').'
				<a class="btn btn-mini btn-success" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/edit?id='.$id).'">编辑</a>
				<a class="btn btn-mini " href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/del?id='.$id).'">删除</a>    
			</div>'; 	
	return $txt;
}

function get_pay_btn($id) {
	#TODO 判断支付情况来显示按钮
	$txt = '<div class="btn-group" >
				<a class="btn btn-mini btn-success" href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/edit?id='.$value['id']).'">设置支付</a>
				<a class="btn btn-mini " href="'.U(MODULE_NAME.'/'.CONTROLLER_NAME.'/del?id='.$value['id']).'">删除</a>           
			</div>'; 	
	return $txt;
}

#Excel
function excel_data($data,$show) {
	$str = '';
	$th = array();
	$tb = array();
	$s1 = explode(',',$show);
	foreach ($s1 as $k) {
		$it = explode(':',$k);
		$rth = explode('|',$it[1]);
		$rtb = explode('|',$it[0]);		
		$th[] = $rth;
		$tb[] = $rtb;
	}

	#表头项
	$str .='<table border="1" cellspacing="0" cellpadding="0" ><thead><tr>';	
	foreach ($th as $h) {
		$str.='<th '.(isset($h[1]) ? 'style="width:'.$h[1].'"' : '').'>'.$h[0].'</th>';
	}
	$str.='</tr></thead>';
	
	#表数据	
	$str.='<tbody>';
	foreach ($data as $dk=>$value) {

		$str .='<tr>';
		foreach ($tb as $b) {
			if (isset($b[1])) {
				if ($b[1]=='get_name') {
					$txt = $b[1]($value[$b[0]],$b[0]); 	
				} else {
					$txt = $b[1]($value[$b[0]]); 	
				}
			} else {
				$txt = $value[$b[0]];
			}
			$str.='<td>'.$txt.'</td>';
		}		
		$str .='</tr>';
	}
	$str.='</tbody>';	
	$str.='</table>';	
	echo $str;
}

#搜索辅助
function search_header($get=false) {
	echo '<div class="searcher"><form action="" method="'.($get ? 'get' : 'post').'" id="search-form" name="search-form" />';	
}
function search_footer($post=array(),$out=false) {
	$post_str = '';
	foreach ($post as $k=>$v) {
		$post_str .= '<input type="hidden" name="'.$k.'" value="'.$v.'" />';
	}
	echo '<div class="controls">	
		'.$post_str.'				
		<button id="submit1" type="submit" name="buttonsearch" value="buttonsearch"   class="btn btn-success">搜索</button>
		'.($out ? '<button id="btnoutput" type="button" name="btnoutput" value="submit" class="btn ">导出</button>' : '').'
	    </div>
		<div class="clear"></div>
		</form>
	</div>';
}

function get_gene_hospital(){
	return 'xxxx';
}
function b_map_select(){
	$htmlscript.='<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=dRUrTiX4xnubXnGkqGrBU8jSfNBtXP6n"></script>';
	$htmlscript.='<div id="allmap" style="height:600px;"></div>';
	$htmlscript.='
	<script type="text/javascript">
	var common = 1;
	var map = new BMap.Map("allmap");
	var point = new BMap.Point(116.404, 39.915);
	map.centerAndZoom(point,20);
// 添加/删除工具条、比例尺控件stars
  setTimeout(function(){
    map.setZoom(15);   
  }, 2000);  //2秒后放大到14级
  map.enableScrollWheelZoom(true);
  var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
  var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
  var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL});
    map.addControl(top_left_control);        
    map.addControl(top_left_navigation);     
    map.addControl(top_right_navigation);  
//定位当前位置s
  function myFun(result){
    var cityName = result.name;
    map.setCenter(cityName);
  }
  var myCity = new BMap.LocalCity();
  myCity.get(myFun);
//定位当前位置e

//鼠标点击拾取坐标s
    map.centerAndZoom(point,20);           
	  map.addEventListener("click",function(e){
	  alert(e.point.lng + "," + e.point.lat);
	  $("#log").val(e.point.lng);
	  $("#lat").val(e.point.lat);
	  map.clearOverlays()
           var gc = new BMap.Geocoder();
           var pt = e.point;
           gc.getLocation(pt, function(rs){
           var addComp = rs.addressComponents;
           address = addComp.province +  addComp.city + addComp.district + addComp.street + addComp.streetNumber;
           var pro=addComp.province.slice(0,-1);
           $("#sysProvinces option").filter(function(){return $(this).text()==pro;}).prop("selected",true);
           $("#address").val(address);
           });
		  var point = new BMap.Point(e.point.lng,e.point.lat);
		  map.centerAndZoom(point,20);
		  var label = new BMap.Label("点击地图移动图标",{offset:new BMap.Size(20,-10)});
		  addMarker(point,label);
     });
//鼠标点击拾取坐标e
       // 编写自定义函数,创建标注
  function addMarker(point,label){
    var marker = new BMap.Marker(point);
    map.addOverlay(marker);
    marker.setLabel(label);
  }
        // 用城市名设置地图中心点s
  function theLocation(city,Size){
    // var city = document.getElementById("cityName").value;
    if(city != ""){
      map.centerAndZoom(city,Size); 
    }
  }
   // 用城市名设置地图中心点e
</script>';
    return $htmlscript;
}

function b_radio_mod($title,$name,$mod,$field='name',$select_value='', $default_value='',$class='',$tips='',$where='',$order='id DESC') {
	$list = D($mod)->where($where)->order($order)->select();
	$all_value  = array();
	foreach ($list as $l) {
		$all_value[$l['id']] = $l[$field];
	}
	
	$htm = c_radio($name, $all_value, $select_value,$class,$attr);
	b_div($title,$htm,$tips);	
}
//通过控制器名字(表的名字) 获取 自增长id
function get_add_id($controllername){
	    //需要严格按照驼峰
        //除了首字母 其余在每一个大写前需要加一个 _ 获取数据表的名字
	    $cname_array=str_split($controllername);
        $cname_string='';
        foreach ($cname_array as $key => $value) {
             $Bigsting = ord($value);
             if($Bigsting>64&&$Bigsting<91&&$key>0){
               $cname_string.='_';
              }
            $cname_string.=strtolower($value);
        }
	    $dbname=C('DB_NAME');//数据库名字
        $dbprefix=C('DB_PREFIX');//表前缀
       $primaryfileinfo=M()->query("SELECT column_name FROM INFORMATION_SCHEMA.`KEY_COLUMN_USAGE`  WHERE table_name='".$dbprefix.$cname_string."' AND CONSTRAINT_SCHEMA='".$dbname."' AND constraint_name='PRIMARY'"); 
       return $primaryfileinfo;
}